package jogoprojetopi;

import Astar.Astar;
import java.awt.Point;
import java.util.ArrayList;


public class PathFinder {


    private static Astar gps;
    private static int map[][];
    private static int width;
    private static int height;



    static public void init( Astar value )
    {
        gps = value;
    }

    static public void loadMap( int m[][], int w, int h, int wall )
    {
        map = m;
        width = w;
        height = h;
        gps.loadMap( m, w, h, wall );
    }

    static public ArrayList<Point> find( Point s, Point e, int h, int t, boolean c)
    {
        return gps.find( s, e, h, t, c );
    }

    static public Point getTileSize() { return new Point( width, height ); }

    static public Point getMapSize() { return new Point( map[0].length, map.length ); }

    static public int[][] getMapMatrix() { return map; }

    static public Point getElementMapPos( Point playerPosition )
    {

        int tileWidth = width / map[0].length;
        int tileHeight = height / map.length;

            for( int rows = 0; rows < map.length; rows++ )
            {
                for( int cols = 0; cols < map[ 0 ].length; cols++ )
                {
                    if(    playerPosition.x >= (( Math.abs( cols * tileWidth ) - tileWidth ) )
                        && playerPosition.x <= (( Math.abs(cols * tileWidth ) + tileWidth  ) )
                        && playerPosition.y >= (( Math.abs( rows * tileHeight ) - tileHeight ))
                        && playerPosition.y <= ( Math.abs(rows * tileHeight ) + tileHeight  ) )
                    {
                         //System.out.println( ((cols * tileWidth) + tileWidth) + " / " + ((rows * tileHeight) + tileHeight) );
                         return new Point( (cols * tileWidth) + tileWidth, (rows * tileHeight) + tileHeight  );
                    }
                }
            }

            return new Point();
    }
 

}
